#include "ActionOpCreation.h"
#include "../View/View.h"

/// <summary>
/// Constructor
/// </summary>
/// <param name="icon"> The icon to show </param>
/// <param name="text"> The text explainer associated with the action </param>
/// <param name="parent"> The action parent </param>
/// <param name="vStatus"> The views status when clicked </param>
/// <param name="op"> An integer that identifies the operation associated with the action </param>
CIOps::ActionOpCreation::ActionOpCreation (const QIcon& icon, const QString& text, QObject* parent, int vStatus, int op)
: QAction (icon, text, parent), viewsStatus (vStatus), operationToCreate (op) { 

    setCheckable (true);
    setChecked (false);
    connect (this, SIGNAL (triggered (bool)), this, SLOT (triggerHandler (bool)));    
}




/// <summary>
/// Slot method to handle the triggered(bool) signal
/// </summary>
void CIOps::ActionOpCreation::triggerHandler (bool c) {
    if (c) {              
        //Throws the signal to allow the application to know which status has
        //to be setted for the 3D views and which operation has to be created
        emit triggered (viewsStatus, operationToCreate);    
        emit triggered (operationToCreate);
    }
    else
        //Throws the signal to allow the application to restore the 3D views 
        //basic status
        emit triggered (CIView::View::NONE, operationToCreate);    
        emit triggered (operationToCreate);
}


/// <summary>
/// Method called to get an integer that identifies the operation associated with the action
/// </summary>
/// <returns> An integer that identifies the operation associated with the action </returns>
int CIOps::ActionOpCreation::GetOperationID() {
    return operationToCreate;
}
